/** 
 * Copyright(C) 2010-2011 <webPrj> LTD. All Rights Reserved.                               
 * Project: webPrj
 * Module ID: <0001>
 * Comments: TODO         
 * JDK version used: <JDK1.6.0_25>                              
 * Author: xiamingxing
 * Create Date：10:35:56
 * Modified By: xiamingxing                              
 * Modified Date: 10:35:56                                  
 * Why & What is modified: <修改原因描述>    
 * Version: V1.0                  
 */
package com.xiamx.platform.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class StringUtil {
	
	/**
	 * 
	 * @description 对字符串进行编码
	 * @author xiamingxing
	 * @param srcStr 需要编码的字符串
	 * @param encStr 编码格式
	 * @return 编码之后的字符串
	 * @throws 
	 */
	public static String encodeStr(String srcStr, String encStr) {
		String resStr = null;
		try {
			resStr = URLEncoder.encode(srcStr, encStr);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return resStr;
	}
	
	/**
	 * 
	 * @description TODO
	 * @author xiamingxing
	 * @param srcStr
	 * @param encStr
	 * @return
	 * @throws
	 */
	public static String decodeStr(String srcStr, String encStr) {
		String resStr = null;
		try {
			resStr = URLDecoder.decode(srcStr, encStr);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return resStr;
	}
	
	public static void main(String []args) {
		String res = encodeStr("你妹","utf-8");
		System.out.println(res);
		res = decodeStr("%E4%BD%A0%E5%A6%B9","utf-8");
		System.out.println(res);
	}

}

